
#include "scanner.hh"
#include <QDebug>
#include <QDir>
#include <QFileInfo>

dsa::Scanner::Scanner()
{
}


dsa::Node* dsa::Scanner::Scan(const QString &path)
{
	QFileInfo info (path);

	return dsa::Scanner::Scan(info);
}

dsa::Node* dsa::Scanner::Scan(const QFileInfo &info)
{
	dsa::Node* node = 0;
	if (info.isFile())
		{
			node = new dsa::FileNode ();
			node->SetSize(info.size());
			node->SetName(info.fileName());
		}
	else if (info.isDir())
		{
			node = new dsa::DirNode ();
			node->SetName(info.fileName());

			QDir dir = info.dir();
			dir.cd(info.fileName());

			fflush(stdout);
			QFileInfoList list = dir.entryInfoList(		QDir::AllEntries
																						 |	QDir::NoDotAndDotDot
																						 |	QDir::Hidden
																						 |	QDir::System
																						 |	QDir::NoSymLinks);

			foreach (QFileInfo fi, list)
				{
					dsa::Node* childNode = dsa::Scanner::Scan(fi);
					if (!childNode)
						{
							continue;
						}
					node->AddNode(childNode);
				}
			node->EvalData();

		}


	return node;
}
